package com.example.springbootrabbitmq.consumer;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Date;

/**
 * @author 墨苍璃
 * @date 2022年09月19日18时01分
 * <p>
 * 死信队列消费者
 */
@Slf4j
@Component
public class DeadLetterQueueConsumer {

    /**
     * 监听死信队列
     *
     * @param message
     * @throws IOException
     */
    @RabbitListener(queues = "QD")
    public void receiveD(Message message) {
        String msg = new String(message.getBody());
        log.info("当前时间：{},收到死信队列信息{}", new Date(), msg);
    }


    public static final String DELAYED_QUEUE_NAME = "delayed.queue";

    /**
     * 监听
     * 延时队列插件
     * 消费者
     *
     * @param message
     */
    @RabbitListener(queues = DELAYED_QUEUE_NAME)
    public void receiveDelayedQueue(Message message) {
        String msg = new String(message.getBody());
        log.info("当前时间：{},收到延时队列的消息：{}", new Date(), msg);
    }

}